home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Archives / GNU / GNUPLOTsrc.lha / term / win.trm < prev    next >
Encoding:
Text File  |  1996-01-22  |  7.9 KB  |  311 lines

  1. /* GNUPLOT - term/win.trm */
  2. /*
  3.  * Copyright (C) 1992   Maurice Castro, Russell Lang
  4.  *
  5.  * Permission to use, copy, and distribute this software and its
  6.  * documentation for any purpose with or without fee is hereby granted, 
  7.  * provided that the above copyright notice appear in all copies and 
  8.  * that both that copyright notice and this permission notice appear 
  9.  * in supporting documentation.
  10.  *
  11.  * Permission to modify the software is granted, but not the right to
  12.  * distribute the modified code.  Modifications are to be distributed 
  13.  * as patches to released version.
  14.  *  
  15.  * This software is provided "as is" without express or implied warranty.
  16.  * 
  17.  *
  18.  * AUTHORS
  19.  * 
  20.  *   Gnuplot for Windows:
  21.  *       Maurice Castro, Russell Lang
  22.  * 
  23.  * There is a mailing list for gnuplot users. Note, however, that the
  24.  * newsgroup 
  25.  *    comp.graphics.gnuplot 
  26.  * is identical to the mailing list (they
  27.  * both carry the same set of messages). We prefer that you read the
  28.  * messages through that newsgroup, to subscribing to the mailing list.
  29.  * (If you can read that newsgroup, and are already on the mailing list,
  30.  * please send a message info-gnuplot-request@dartmouth.edu, asking to be
  31.  * removed from the mailing list.)
  32.  *
  33.  * The address for mailing to list members is
  34.  *       info-gnuplot@dartmouth.edu
  35.  * and for mailing administrative requests is 
  36.  *       info-gnuplot-request@dartmouth.edu
  37.  * The mailing list for bug reports is 
  38.  *       bug-gnuplot@dartmouth.edu
  39.  * The list of those interested in beta-test versions is
  40.  *       info-gnuplot-beta@dartmouth.edu
  41.  */
  42.  
  43.  
  44. /* This file implements the terminal and printer display for gnuplot  */
  45. /* under Microsoft Windows. The code currently compiles only with the */
  46. /* Borland C++ 3.1 compiler.                                          */
  47. /*                                                                    */
  48. /* The modifications to allow Gnuplot to run under Windows were made  */
  49. /* by Maurice Castro (maurice@bruce.cs.monash.edu.au)                 */
  50. /* and Russell Lang (rjl@monu1.cc.monash.edu.au)         19 Nov 1992  */
  51. /*                                                                    */
  52.  
  53. /* Edit this file with tabstop=4 (vi :se ts=4)                        */
  54.  
  55. /*
  56.  * adapted to the new terminal layout by Stefan Bodewig (Dec. 1995)
  57.  */
  58.  
  59. #ifndef GOT_DRIVER_H
  60. #include "driver.h"
  61. #endif
  62.  
  63. #ifdef TERM_REGISTER
  64. register_term(windows)
  65. #endif
  66.  
  67. #ifdef TERM_PROTO
  68. TERM_PUBLIC void WIN_options __P((void));
  69. TERM_PUBLIC int WIN_scale __P((void));
  70. TERM_PUBLIC void WIN_init __P((void));
  71. TERM_PUBLIC void WIN_reset __P((void));
  72. TERM_PUBLIC void WIN_text __P((void));
  73. TERM_PUBLIC void WIN_graphics __P((void));
  74. TERM_PUBLIC void WIN_move __P((unsigned int x, unsigned int y));
  75. TERM_PUBLIC void WIN_vector __P((unsigned int x, unsigned int y));
  76. TERM_PUBLIC void WIN_linetype __P((int lt));
  77. TERM_PUBLIC void WIN_put_text __P((unsigned int x, unsigned int y, char *str));
  78. TERM_PUBLIC int WIN_justify_text __P((enum JUSTIFY mode));
  79. TERM_PUBLIC int WIN_text_angle __P((int ang));
  80. TERM_PUBLIC void WIN_point __P((unsigned int x, unsigned int y, int number));
  81.  
  82. /* Initialization values - Guess Now Scale later */
  83. #define WIN_XMAX (2400)
  84. #define WIN_YMAX (1800)
  85. #define WIN_HCHAR (WIN_XMAX/75) 
  86. #define WIN_VCHAR (WIN_YMAX/25)
  87. #define WIN_HTIC (WIN_XMAX/160)
  88. #define WIN_VTIC WIN_HTIC
  89. #endif /* TERM_PROTO */
  90.  
  91. #ifndef TERM_PROTO_ONLY
  92. #ifdef TERM_BODY
  93. FILE * open_printer __P((void));
  94. void close_printer __P((void));
  95. void screen_dump __P((void));
  96.  
  97. #include <windows.h>
  98. #include "../win/wgnuplib.h"
  99.  
  100. extern GW graphwin;
  101.  
  102. char win_prntmp[256];    /* printer temporary file */
  103.  
  104.  
  105. /* Interface routines - create list of actions for Windows */
  106.  
  107. TERM_PUBLIC void WIN_options()
  108. {
  109.     if (!END_OF_COMMAND) {
  110.         if (almost_equals(c_token,"d$efault")) {
  111.             graphwin.color=TRUE;
  112.             strcpy(graphwin.fontname,WINFONT);
  113.             graphwin.fontsize = WINFONTSIZE;
  114.             c_token++;
  115.         }
  116.     }
  117.  
  118.     if (!END_OF_COMMAND) {
  119.         if (almost_equals(c_token,"m$onochrome")) {
  120.             graphwin.color=FALSE;
  121.             c_token++;
  122.         }
  123.         else if (almost_equals(c_token,"c$olor")) {
  124.             graphwin.color=TRUE;
  125.             c_token++;
  126.         }
  127.     }
  128.  
  129.     if (!END_OF_COMMAND && isstring(c_token)) {
  130.         quote_str(graphwin.fontname,c_token, MAX_ID_LEN);
  131.         c_token++;
  132.     }
  133.  
  134.     if (!END_OF_COMMAND) {
  135.         /* We have font size specified */
  136.         struct value a;
  137.         graphwin.fontsize = (int)real(const_express(&a));
  138.     }
  139.  
  140.     if (graphwin.fontname[0] == '\0')
  141.       sprintf(term_options,"%s", graphwin.color ? "color" :  "monochrome");
  142.     else
  143.       sprintf(term_options,"%s \"%s\" %d", graphwin.color ? "color" :  "monochrome" ,
  144.         graphwin.fontname, graphwin.fontsize);
  145.     if (IsWindow(graphwin.hWndGraph) && IsIconic(graphwin.hWndGraph)) {
  146.         ShowWindow(graphwin.hWndGraph, SW_SHOWNORMAL);
  147.     }
  148.     GraphRedraw(&graphwin);
  149. }
  150.  
  151. /* We don't actually do scaling, but we need to fix up the text size
  152.  * if the user has resized the window */
  153. int WIN_scale()
  154. {
  155.     term->h_char = graphwin.hchar;
  156.     term->v_char = graphwin.vchar;
  157.     sprintf(term_options,"%s \"%s\" %d", graphwin.color ? "color" :  "monochrome" ,
  158.         graphwin.fontname, graphwin.fontsize);
  159.     return FALSE ;    /* can't be done */
  160. }
  161.  
  162. TERM_PUBLIC void WIN_init()
  163. {
  164.     if (!graphwin.hWndGraph) {
  165.         graphwin.xmax = WIN_XMAX;
  166.         graphwin.ymax = WIN_YMAX;
  167.         graphwin.htic = WIN_HTIC;
  168.         graphwin.vtic = WIN_VTIC;
  169.         GraphInit(&graphwin);
  170. #ifdef WIN32
  171.         SetClassLong(graphwin.hWndGraph, GCL_HICON, (LONG)LoadIcon(graphwin.hInstance, "grpicon"));
  172. #else
  173.         SetClassWord(graphwin.hWndGraph, GCW_HICON, LoadIcon(graphwin.hInstance, "grpicon"));
  174. #endif
  175.         graphwin.resized = FALSE;
  176.     }
  177. }
  178.  
  179.  
  180. TERM_PUBLIC void WIN_reset()
  181. {
  182. }
  183.  
  184. TERM_PUBLIC void WIN_text()
  185. {
  186.     GraphEnd(&graphwin);
  187. }
  188.  
  189. TERM_PUBLIC void WIN_graphics()
  190. {
  191.     GraphStart(&graphwin);
  192. }
  193.  
  194. TERM_PUBLIC void WIN_move(x, y)
  195. unsigned int x, y;
  196. {
  197.     GraphOp(&graphwin, W_move, x, y, NULL);
  198. }
  199.  
  200. TERM_PUBLIC void WIN_vector(x,y)
  201. unsigned int x, y;
  202. {
  203.     GraphOp(&graphwin, W_vect, x, y, NULL);
  204. }
  205.  
  206. TERM_PUBLIC void WIN_linetype(lt)
  207. int lt;
  208. {
  209.     GraphOp(&graphwin, W_line_type, lt, 0, NULL);
  210. }
  211.  
  212. TERM_PUBLIC void WIN_put_text(x,y,str)
  213. unsigned int x, y;
  214. char *str;
  215. {
  216.     GraphOp(&graphwin, W_put_text, x, y, str);
  217. }
  218.  
  219. TERM_PUBLIC int WIN_justify_text(mode)
  220. enum JUSTIFY mode;
  221. {
  222.     GraphOp(&graphwin, W_justify, mode, 0, NULL);
  223.     return(TRUE);
  224. }
  225.  
  226. TERM_PUBLIC int WIN_text_angle(ang)
  227. int ang;
  228. {
  229.     if (graphwin.rotate)
  230.         GraphOp(&graphwin, W_text_angle, ang, 0, NULL);
  231.     return graphwin.rotate;
  232. }
  233.  
  234. TERM_PUBLIC void WIN_point(x,y,number)
  235. unsigned int x,y;
  236. int number;
  237. {
  238.     /* draw point shapes later to save memory */
  239.     graphwin.htic = term->h_tic / 2;     /* size of point symbols */
  240.     graphwin.vtic = term->v_tic / 2;
  241.     if (number>=0)
  242.         number %= POINT_TYPES;
  243.     number += 1;
  244.     GraphOp(&graphwin, W_dot + number, x, y, NULL);
  245. }
  246.  
  247.  
  248. /* Windows PRN emulation */
  249. FILE *
  250. open_printer()
  251. {
  252. char *temp;
  253.     if ((temp = getenv("TEMP")) == (char *)NULL)
  254.         *win_prntmp='\0';
  255.     else  {
  256.         strncpy(win_prntmp,temp,MAX_ID_LEN-1);
  257.         /* stop X's in path being converted by mktemp */
  258.         for (temp=win_prntmp; *temp; temp++)
  259.             *temp = tolower(*temp);
  260.         if ( strlen(win_prntmp) && (win_prntmp[strlen(win_prntmp)-1]!='\\') )
  261.             strcat(win_prntmp,"\\");
  262.     }
  263.     strncat(win_prntmp, "_gptmp",MAX_ID_LEN-strlen(win_prntmp));
  264.     strncat(win_prntmp, "XXXXXX",MAX_ID_LEN-strlen(win_prntmp));
  265.     mktemp(win_prntmp);
  266.     return fopen(win_prntmp, "w");
  267. }
  268.  
  269. void
  270. close_printer()
  271. {
  272.     fclose(outfile);
  273.     DumpPrinter(graphwin.hWndGraph, graphwin.Title, win_prntmp);
  274. }
  275.  
  276. void
  277. screen_dump(void)
  278. {
  279.     GraphPrint(&graphwin);
  280. }
  281.  
  282. #endif /* TERM_BODY */
  283.  
  284. #ifdef TERM_TABLE
  285.  
  286. TERM_TABLE_START(win_driver)
  287.     "windows", "Microsoft Windows",
  288.        WIN_XMAX, WIN_YMAX, WIN_VCHAR, WIN_HCHAR, 
  289.        WIN_VTIC, WIN_HTIC, WIN_options, WIN_init, WIN_reset, 
  290.        WIN_text, null_scale, WIN_graphics, WIN_move, WIN_vector,
  291.        WIN_linetype, WIN_put_text, WIN_text_angle, 
  292.        WIN_justify_text, WIN_point, do_arrow, set_font_null
  293. TERM_TABLE_END(win_driver)
  294.  
  295. #undef LAST_TERM
  296. #define LAST_TERM win_driver
  297.  
  298. #endif /* TERM_TABLE */
  299. #endif /* TERM_PROTO_ONLY */
  300.  
  301. /*
  302.  * NAME: windows
  303.  *
  304.  * OPTIONS: monochrome|colour (default colour)
  305.  *        fontname fontsize (defaults taken from the system)
  306.  *
  307.  * SUPPORTS: Microsoft Windows
  308.  *
  309.  * Further Info: none
  310.  *
  311.  */